rebol[]

do[
;debug
print ["debugging" second split-path system/options/script]
system/options/quiet: false
]

global: system/words ; for exports

???: func['word value][
	print[mold word mold/all :value]
	do reduce[word :value]
]

stop: func[][
	;wait 4 
	quit
]

; experimental

; trying explicit delemiter
.: func [arg [any-type!]] [
	get/any 'arg
]

mark-record: func[blk ofs][
	new-line skip tail blk negate ofs true
]


;conversions

; based on http://snippets.dzone.com/posts/show/1456	
url-encode: func [
    {URL-encode a string}
    data "String to encode"
    /local normal-char out
][
    normal-char: charset [
        #"A" - #"Z" #"a" - #"z"
        #"@" #"." #"*" #"-" #"_"
        #"0" - #"9"
    ]
    out: copy""
        foreach char data [
            append out either find normal-char char [char] [
                rejoin ["%" to-string skip tail (to-hex to-integer char) -2]
            ]
        ]
    out
]

; got chars somewhere linked from http://earl.strain.at/space/rebXR

xml-chars-map: ["&" "&amp;" "<" "&lt;" ">" "&gt;" "'" "&apos;" "^"" "&quot;"]
normal-xml-chars: complement charset extract xml-chars-map 2

encode-xml-string: func [string /local out tp1 p2][
    out: copy "" 
    parse/all string [
        any [
            p1: any normal-xml-chars p2: copy char skip (
                insert/part tail out p1 p2 
                insert tail out select xml-chars-map char
            )
        ] 
        p1: (insert tail out p1)
    ] 
    out
]

de-xml:
decode-xml-string: func[string /local tag][
	out: copy""
    parse/all string [
        any [
            p1: to "&" p2: copy tag thru ";" (
                insert/part tail out p1 p2 
                insert tail out first back find xml-chars-map tag
            )
        ] 
        p1: (insert tail out p1)
    ] 
    out
]
